<template>
  <div>
    <home-header></home-header>
    <home-swiper :list="swiperList"></home-swiper>
    <home-icons :list="iconList"></home-icons>
    <top-list :list="topItems"></top-list>
    <home-guess :list="likeLists"></home-guess>
    <home-week :list="weekLists"></home-week>
  </div>
</template>

<script>
import HomeHeader from './component/Header.vue'
import HomeSwiper from './component/Swiper.vue'
import HomeIcons from './component/Icons.vue'
import TopList from './component/TopList.vue'
import HomeGuess from './component/Guesslike.vue'
import HomeWeek from './component/Weekend.vue'
import axios from 'axios'
import { mapState } from 'vuex'

export default {
  name: 'Home',
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcons,
    TopList,
    HomeGuess,
    HomeWeek
  },
  data () {
    return {
      lastCity: '',
      topItems: [],
      swiperList: [],
      weekLists: [],
      iconList: [],
      likeLists: []
    }
  },
  computed: {
    ...mapState(['city'])
  },
  methods: {
    getHomeInfo () {
      axios.get('api/cityDetail/cityname/' + this.city)
        .then(this.getHomeInfoSucc)
    },
    getHomeInfoSucc (res) {
      // console.log(res.data.cityDetail[0].cityName)
      const cityData = res.data.cityDetail[0]
      if (cityData) {
        const cityData = res.data.cityDetail[0].cityDetail
        this.swiperList = cityData.banners
        this.iconList = cityData.icons
        this.topItems = cityData.hostList
        this.likeLists = cityData.likeList
        this.weekLists = cityData.weekendTrip
      }
    }
  },
  mounted () {
    this.lastCity = this.city
    this.getHomeInfo()
  },
  activated () {
    if (this.lastCity !== this.city) {
      this.lastCity = this.city
      this.getHomeInfo()
    }
  }
}
</script>

<style lang="stylus">
  body
    background: #f5f5f5
</style>
